package com.shjn.squirrel.fragment;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.shjn.squirrel.MainActivity;

/**
 * Fragment基类，用于处理通用操作
 */
public class BaseFragment extends Fragment {

    protected View mView;
    protected MainActivity mActivity;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mActivity = (MainActivity) activity;
        Log.i("info", getClass().getSimpleName() + ":onAttach");
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);//API23以上被回调
        mActivity = (MainActivity) getActivity();
        Log.i("info", getClass().getSimpleName() + ":onAttach_context");
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i("info", getClass().getSimpleName() + ":onCreate");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    public View createView(LayoutInflater inflater, int resource, ViewGroup root) {
        Log.i("info", getClass().getSimpleName() + ":onCreateView");
        mView = inflater.inflate(resource, root, false);
        return mView;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Log.i("info", getClass().getSimpleName() + ":onViewCreated");
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Log.i("info", getClass().getSimpleName() + ":onActivityCreated");
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.i("info", getClass().getSimpleName() + ":onStart");
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.i("info", getClass().getSimpleName() + ":onResume");

    }

    @Override
    public void onPause() {
        super.onPause();
        Log.i("info", getClass().getSimpleName() + ":onPause");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.i("info", getClass().getSimpleName() + ":onStop");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.i("info", getClass().getSimpleName() + ":onDestroyView");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i("info", getClass().getSimpleName() + ":onDestroy");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Log.i("info", getClass().getSimpleName() + ":onDetach");
    }

}
